package com.xxl.job.executor.service.jobhandler;

import com.xxl.job.core.context.XxlJobHelper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;

@Service
//@Component
public class ExecutorServiceImpl {
    @Async("syncBusinessTaskExecutor")
    public void syncBusinessTaskExecutor(String tableName) {
        switch (tableName) {
            case "tab1":
                countdown(5);
                XxlJobHelper.log("XXL-JOB, Hello World 1.");
                break;
            case "tab2":
                countdown(5);
                XxlJobHelper.log("XXL-JOB, Hello World 2.");
                break;
        }
    }

    public void countdown(int seconds) {
        for (int i = seconds; i > 0; i--) {
            XxlJobHelper.log(i + "秒");
            try {
                TimeUnit.SECONDS.sleep(1); // 用更清晰的时间单位
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        XxlJobHelper.log("倒计时结束!");
    }

}
